package com.atguigu.principle.ocp;

/**
 * @author ccc
 * @create 2020-07-10 18:47
 */
public class Ocp {
    public static void main(String[] args) {
        GraphicEditor graphicEditor = new GraphicEditor();
        graphicEditor.drawShape(new Triangle());
        graphicEditor.drawShape(new Circle());
        graphicEditor.drawShape(new Rectangle());

    }
}

//画图的类【使用方】
class GraphicEditor {
    //接收Share对象，然后根据type绘制不同的图形
    public void drawShape(Shape s) {
        if (s.m_type == 1)
            drawRectangle(s);
        else if (s.m_type == 2)
            drawCircle(s);
        else if (s.m_type == 3)
            drawTriangle(s);
    }
    public void drawRectangle(Shape r) {
        System.out.println("矩形");
    }
    public void drawCircle(Shape r) {
        System.out.println("圆形");
    }
    public void drawTriangle(Shape r) {
        System.out.println("三角形");
    }
}

class Shape {
    int m_type;
}

//矩形
class Rectangle extends Shape {
    Rectangle() {
        super.m_type = 1;
    }
}
//圆
class Circle extends Shape {
    Circle() {
        super.m_type = 2;
    }
}

class Triangle extends Shape{
    public Triangle() {
        super.m_type = 3;
    }
}